<template>
  <div class="count-box">
    <button @click="handelSub" class="minus" :disabled ="buttonStatus" >-</button>
    <input :value="value" type="text" class="inp">
    <button  @click="handelAdd" class="add">+</button>
  </div>
</template>

<script>
export default {
// 父组件传了value来
  data () {
    return {
      buttonStatus: false
    }
  },
  props: {
    value: {
      type: Number,
      default: 1
    }
  },
  methods: {
    handelSub () {
      if (this.value <= 1) {
        this.buttonStatus = true
        return
      }
      // 向上触发'input'事件 因为父组件是使用v-model向组件传数据的
      this.$emit('input', this.value - 1)
    },
    handelAdd () {
      this.$emit('input', this.value + 1)
    }
  }
}
</script>

<style lang="less" scoped>
.count-box{
  width: 100px;
  display: flex;
  .minus, .add{
      width: 30px;
      height: 30px;
      outline: none;
      border: none;
      background-color: #efefef;
  }
  .inp{
    width: 40px;
    height: 30px;
    outline: none;
    border: none;
    margin: 0 5px;
    background-color: #efefef;
    text-align: center;
  }
}

</style>
